<html>
<head><meta charset="utf-8"><title>static assertions? · t-lang · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/index.html">t-lang</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/static.20assertions.3F.html">static assertions?</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="194715119"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/static%20assertions%3F/near/194715119" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/static.20assertions.3F.html#194715119">(Apr 20 2020 at 18:33)</a>:</h4>
<p>Now that we have good const evaluation, what would it take to reintroduce a static assertion mechanism?</p>



<a name="194715144"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/static%20assertions%3F/near/194715144" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/static.20assertions.3F.html#194715144">(Apr 20 2020 at 18:33)</a>:</h4>
<p>We have things like <code>compile_error!</code>, but as far as I can tell that's unconditional.</p>



<a name="194715252"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/static%20assertions%3F/near/194715252" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/static.20assertions.3F.html#194715252">(Apr 20 2020 at 18:34)</a>:</h4>
<p>I'd like to be able to write things like this:</p>
<div class="codehilite"><pre><span></span><span class="n">static_assert</span><span class="o">!</span><span class="p">(</span><span class="n">size_of</span>::<span class="o">&lt;</span><span class="kt">usize</span><span class="o">&gt;</span><span class="p">()</span><span class="w"> </span><span class="o">==</span><span class="w"> </span><span class="n">size_of</span>::<span class="o">&lt;</span><span class="kt">u64</span><span class="o">&gt;</span><span class="p">());</span><span class="w"></span>
<span class="n">static_assert</span><span class="o">!</span><span class="p">(</span><span class="n">X_SIZE</span><span class="w"> </span><span class="o">+</span><span class="w"> </span><span class="n">Y_SIZE</span><span class="w"> </span><span class="o">+</span><span class="w"> </span><span class="n">Z_SIZE</span><span class="w"> </span><span class="o">==</span><span class="w"> </span><span class="n">BLOCK_SIZE</span><span class="p">);</span><span class="w"></span>
</pre></div>



<a name="194717542"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/static%20assertions%3F/near/194717542" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/static.20assertions.3F.html#194717542">(Apr 20 2020 at 18:51)</a>:</h4>
<p>There's already a library providing this: <a href="https://docs.rs/static_assertions/1.1.0/static_assertions/" title="https://docs.rs/static_assertions/1.1.0/static_assertions/">https://docs.rs/static_assertions/1.1.0/static_assertions/</a> fwiw</p>



<a name="194718190"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/static%20assertions%3F/near/194718190" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/static.20assertions.3F.html#194718190">(Apr 20 2020 at 18:56)</a>:</h4>
<p>but I'd also love to see it in std</p>



<a name="194719229"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/static%20assertions%3F/near/194719229" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/static.20assertions.3F.html#194719229">(Apr 20 2020 at 19:05)</a>:</h4>
<p>Right. That would, among other things, provide much better error messages.</p>



<a name="194719356"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/static%20assertions%3F/near/194719356" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/static.20assertions.3F.html#194719356">(Apr 20 2020 at 19:06)</a>:</h4>
<p>That crate uses the "constant array with negative size" trick.</p>



<a name="194720064"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/static%20assertions%3F/near/194720064" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Sebastian Malton <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/static.20assertions.3F.html#194720064">(Apr 20 2020 at 19:12)</a>:</h4>
<p>Which feels like a C style of solution, would it be possible to provide a minimal subset of assertions and then leave higher order items to crates?</p>



<a name="194720477"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/static%20assertions%3F/near/194720477" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/static.20assertions.3F.html#194720477">(Apr 20 2020 at 19:16)</a>:</h4>
<p>I think any initial solution would likely be just the single static_assert macro (and maybe _eq, I guess).</p>



<a name="194721430"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/static%20assertions%3F/near/194721430" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Dylan MacKenzie (ecstatic-morse) <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/static.20assertions.3F.html#194721430">(Apr 20 2020 at 19:26)</a>:</h4>
<p>Stabilizing <a href="https://github.com/rust-lang/rust/issues/49146" title="https://github.com/rust-lang/rust/issues/49146">#49146</a> and <a href="https://github.com/rust-lang/rust/issues/51999" title="https://github.com/rust-lang/rust/issues/51999">#51999</a> is the path forward here. If you also guarantee that <code>const</code> items outside of an impl block will be evaluated, even if they are unused, <code>static_assert</code> is just a macro that expands to <code>const _: () = assert!($expr);</code>. <code>static_assertions</code> already depends on that last part.</p>



<a name="194733238"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/static%20assertions%3F/near/194733238" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/static.20assertions.3F.html#194733238">(Apr 20 2020 at 21:05)</a>:</h4>
<p>I'm not looking for a way to clean up the <code>const _: ()</code> trick. I'd like to have a conditional version of <code>compile_error!</code>, as a top-level construct.</p>



<a name="194743847"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/static%20assertions%3F/near/194743847" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Dylan MacKenzie (ecstatic-morse) <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/static.20assertions.3F.html#194743847">(Apr 20 2020 at 23:01)</a>:</h4>
<p>What would the difference be between the following and what you're looking for?</p>
<div class="codehilite"><pre><span></span><span class="n">macro_rules</span><span class="o">!</span><span class="w"> </span><span class="n">static_assert</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="p">(</span><span class="cp">$expr</span>:<span class="nc">expr</span><span class="p">,</span><span class="w"> </span><span class="cp">$msg</span>:<span class="nc">lit</span><span class="p">)</span><span class="w"> </span><span class="o">=&gt;</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="k">const</span><span class="w"> </span><span class="n">_</span>: <span class="p">()</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">assert</span><span class="o">!</span><span class="p">(</span><span class="cp">$expr</span><span class="p">,</span><span class="w"> </span><span class="cp">$msg</span><span class="p">);</span><span class="w"> </span><span class="p">}</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>
</pre></div>


<p>If <a href="https://github.com/rust-lang/rust/issues/51999" title="https://github.com/rust-lang/rust/issues/51999">#51999</a> were stabilized, we would no longer have to rely on triggering an index out-of-bounds error, and you would get the same message at compile-time as if the <code>assert</code> had triggered at runtime.</p>



<a name="194744564"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/static%20assertions%3F/near/194744564" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Dylan MacKenzie (ecstatic-morse) <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/static.20assertions.3F.html#194744564">(Apr 20 2020 at 23:12)</a>:</h4>
<p>At that point, the output of <code>static_assert</code> and <code>compile_error</code> should be the same, except that errors from <code>compile_error</code> show up during macro expansion, while those from <code>static_assert</code> won't be shown until const-eval happens.</p>



<a name="194744704"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/static%20assertions%3F/near/194744704" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/static.20assertions.3F.html#194744704">(Apr 20 2020 at 23:14)</a>:</h4>
<p>The primary difference would be that I'd like to not have the availability and timeline of static assertions depend on a mechanism to ensure that such constants get computed and not optimized out.</p>



<a name="194744738"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/static%20assertions%3F/near/194744738" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/static.20assertions.3F.html#194744738">(Apr 20 2020 at 23:15)</a>:</h4>
<p><code>compile_error</code> exists today. The equivalent of <code>compile_error_if</code> seems extremely straightforward to implement.</p>



<a name="194744815"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/static%20assertions%3F/near/194744815" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/static.20assertions.3F.html#194744815">(Apr 20 2020 at 23:16)</a>:</h4>
<p>And in the future, if we implement and stabilize the multiple issues needed to make <code>const _: () = assert!(...);</code> work, we can always change the definition of <code>static_assert</code>.</p>



<a name="194744829"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/static%20assertions%3F/near/194744829" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/static.20assertions.3F.html#194744829">(Apr 20 2020 at 23:16)</a>:</h4>
<p>It's not like doing so locks us in; we could move it from the language to the library easily enough if we want to do so.</p>



<a name="194745077"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/static%20assertions%3F/near/194745077" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Dylan MacKenzie (ecstatic-morse) <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/static.20assertions.3F.html#194745077">(Apr 20 2020 at 23:21)</a>:</h4>
<p><span class="user-mention silent" data-user-id="239881">Josh Triplett</span> <a href="#narrow/stream/213817-t-lang/topic/static.20assertions.3F/near/194744738" title="#narrow/stream/213817-t-lang/topic/static.20assertions.3F/near/194744738">said</a>:</p>
<blockquote>
<p><code>compile_error</code> exists today. The equivalent of <code>compile_error_if</code> seems extremely straightforward to implement.</p>
</blockquote>
<p>I'm not convinced that this part is true, which is why I'm more bullish on a <code>#![feature(const_panic)]</code> based approach I think. Have you looked at implementing <code>compile_error_if</code>? If it is easy to do, then I would be quite happy to have it ASAP, since like you say we can change the implementation later.</p>



<a name="194745164"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/static%20assertions%3F/near/194745164" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/static.20assertions.3F.html#194745164">(Apr 20 2020 at 23:22)</a>:</h4>
<p>For the record, I <em>would</em> like panic/assert in const to work too, once that's ready. :)</p>



<a name="194745232"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/static%20assertions%3F/near/194745232" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/static.20assertions.3F.html#194745232">(Apr 20 2020 at 23:23)</a>:</h4>
<p>And to answer your question: superficially, yes.</p>



<a name="194830314"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/static%20assertions%3F/near/194830314" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/static.20assertions.3F.html#194830314">(Apr 21 2020 at 16:48)</a>:</h4>
<p>Something I would very much like is clear error messages --</p>



<a name="194830336"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/static%20assertions%3F/near/194830336" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/static.20assertions.3F.html#194830336">(Apr 21 2020 at 16:48)</a>:</h4>
<p>you won't get this through the static-assert library</p>



<a name="194830347"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/static%20assertions%3F/near/194830347" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/static.20assertions.3F.html#194830347">(Apr 21 2020 at 16:48)</a>:</h4>
<p>but maybe an <code>assert!</code> based solution would be able to do so</p>



<a name="194830411"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/static%20assertions%3F/near/194830411" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/static.20assertions.3F.html#194830411">(Apr 21 2020 at 16:49)</a>:</h4>
<p>in any case I think we should totally aim for seamless integration</p>



<a name="194830448"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/static%20assertions%3F/near/194830448" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/static.20assertions.3F.html#194830448">(Apr 21 2020 at 16:49)</a>:</h4>
<p>it's worth pointing out that the static assert library lets you guarantee all manner of things, only some of which would be suitable for a <code>static_assert!</code></p>



<a name="194830452"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/static%20assertions%3F/near/194830452" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/static.20assertions.3F.html#194830452">(Apr 21 2020 at 16:49)</a>:</h4>
<p>it's got some pretty clever hacks in there</p>



<a name="194831807"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/static%20assertions%3F/near/194831807" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/static.20assertions.3F.html#194831807">(Apr 21 2020 at 16:59)</a>:</h4>
<p>I personally wonder if, since <code>assert!</code> is already pretty embedded in the compiler, we could make <em>it</em> just work in item context, instead of needing a separate macro. But that might be confusing too if it's not a real macro afterwards</p>



<a name="194832496"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/static%20assertions%3F/near/194832496" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/static.20assertions.3F.html#194832496">(Apr 21 2020 at 17:04)</a>:</h4>
<p>I think we need very little in the language itself, just the ability to do a compile-time static assert on a condition and provide a message. The rest can go in some combination of the standard library and other crates.</p>



<a name="194832589"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/static%20assertions%3F/near/194832589" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/static.20assertions.3F.html#194832589">(Apr 21 2020 at 17:05)</a>:</h4>
<p><span class="user-mention" data-user-id="116122">@simulacrum</span> I think I'd rather not have <code>assert!</code> do too much DWIM based on context.</p>



<a name="194833936"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/static%20assertions%3F/near/194833936" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/static.20assertions.3F.html#194833936">(Apr 21 2020 at 17:16)</a>:</h4>
<p>Yeah -- though I wonder if a more general "const expressions are items" could be an interesting idea. But probably not much benefit, I agree.</p>



<a name="194837029"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/static%20assertions%3F/near/194837029" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/static.20assertions.3F.html#194837029">(Apr 21 2020 at 17:39)</a>:</h4>
<p>well</p>



<a name="194837044"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/static%20assertions%3F/near/194837044" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/static.20assertions.3F.html#194837044">(Apr 21 2020 at 17:39)</a>:</h4>
<p>keep in mind that</p>
<div class="codehilite"><pre><span></span><span class="k">fn</span> <span class="nf">foo</span><span class="p">()</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="k">fn</span> <span class="nf">bar</span><span class="p">()</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="p">}</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>
</pre></div>


<p>works</p>



<a name="194837055"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/static%20assertions%3F/near/194837055" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/static.20assertions.3F.html#194837055">(Apr 21 2020 at 17:39)</a>:</h4>
<p>I think that's one of those design decisions I would reverse if we could</p>



<a name="194837118"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/static%20assertions%3F/near/194837118" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/static.20assertions.3F.html#194837118">(Apr 21 2020 at 17:40)</a>:</h4>
<p>but regardless, it makes <code>fn foo() { assert!(...); }</code> kind of "ambiguous"</p>



<a name="194837155"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/static%20assertions%3F/near/194837155" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/static.20assertions.3F.html#194837155">(Apr 21 2020 at 17:40)</a>:</h4>
<p>I do use items-in-functions occasionally, and would want that to still work.</p>



<a name="194837276"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/static%20assertions%3F/near/194837276" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/static.20assertions.3F.html#194837276">(Apr 21 2020 at 17:41)</a>:</h4>
<p>That's a good point. I don't mind so much having a separate macro</p>



<a name="194837280"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/static%20assertions%3F/near/194837280" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/static.20assertions.3F.html#194837280">(Apr 21 2020 at 17:41)</a>:</h4>
<p>That said, I did put something in the 2021 ideas list that talked about improving the handling of <code>const</code> inside a block.</p>



<a name="194837374"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/static%20assertions%3F/near/194837374" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/static.20assertions.3F.html#194837374">(Apr 21 2020 at 17:42)</a>:</h4>
<p>I'd like to have order actually matter. I don't think it should work to forward-reference a constant declared later in a code block.</p>



<a name="194837421"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/static%20assertions%3F/near/194837421" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/static.20assertions.3F.html#194837421">(Apr 21 2020 at 17:42)</a>:</h4>
<p>well so</p>



<a name="194837458"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/static%20assertions%3F/near/194837458" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/static.20assertions.3F.html#194837458">(Apr 21 2020 at 17:43)</a>:</h4>
<p>ok, let's not discuss nested items for the time being</p>



<a name="194837481"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/static%20assertions%3F/near/194837481" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/static.20assertions.3F.html#194837481">(Apr 21 2020 at 17:43)</a>:</h4>
<p><em>but</em> it might make sense to deprecate some subset because "IDE friendly"</p>



<a name="194837678"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/static%20assertions%3F/near/194837678" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/static.20assertions.3F.html#194837678">(Apr 21 2020 at 17:44)</a>:</h4>
<p>my understanding (though only through talking/hearing <span class="user-mention" data-user-id="133169">@matklad</span>) is that IDEs care far more about our "macros produce arbitrary items" problem :)</p>



<a name="194837710"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/static%20assertions%3F/near/194837710" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/static.20assertions.3F.html#194837710">(Apr 21 2020 at 17:45)</a>:</h4>
<p>but yeah</p>



<a name="194841571"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/static%20assertions%3F/near/194841571" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/static.20assertions.3F.html#194841571">(Apr 21 2020 at 18:15)</a>:</h4>
<p>well, both are bad</p>



<a name="194841624"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/static%20assertions%3F/near/194841624" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/static.20assertions.3F.html#194841624">(Apr 21 2020 at 18:16)</a>:</h4>
<p>but one is easy to fix :P</p>



<a name="196239440"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/static%20assertions%3F/near/196239440" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Nikolai Vazquez <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/static.20assertions.3F.html#196239440">(May 04 2020 at 20:59)</a>:</h4>
<p>Author of <code>static_assertions</code> crate here. I'm planning to turn <code>const_assert!</code> into <code>const _: () = assert!(condition, message);</code> when that becomes stable.</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>